Chris Pollett > Old Classes > CS174
( Print View )

Student Corner:
  [Submit Sec2]
  [Grades Sec2]

  [Submit Sec3]
  [Grades Sec3]

  [
Lecture Notes]
  [Discussion Board]

Course Info:
  [Texts & Links]
  [Description]
  [Course Outcomes]
  [Outcomes Matrix]
  [Course Schedule]
  [Grading]
  [Requirements/HW/Quizzes]
  [Class Protocols]
  [Exam Info]
  [Regrades]
  [University Policies]
  [Announcements]

HW Assignments:
  [Hw1]  [Hw2]  [Hw3]
  [Hw4]  [Hw5]  [Quizzes]

Practice Exams:
  [Midterm]  [Final]

                           












HW#3 --- last modified February 06 2019 04:10:00..

Solution set.

Due date: Nov 2

Files to be submitted:
  Hw3.zip

Purpose: To write an application that uses databases and uses the MVA design pattern

Related Course Outcomes:

The main course outcomes covered by this assignment are:

CLO3 -- Write server-side scripts that process HTML forms.

CLO5 -- Develop and deploy web applications that involve components, web services, and databases.

Specification:

For this homework, you will develop a web site "Five Thousand Characters", a site that allows users to post and rate each others writings.

What Your Site Should Look Like

The site should consist of three main views: The Landing Page view, the Write Something view, the Read A Story view.

The Landing View

The landing page should have centered at its top in an h1 tag, "Five Thousand Characters". This should also be the title of the page. Beneath this there should be a link: Write Something! that takes one to the Write Something view. Under this link, it should say: Check out what people are writing... There should be a form consisting of a text field with placeholder Phrase Filter, a dropdown populated from a database table of genres with the default genre being "All Genres", and a Go button. Beneath this should be three, h3-titled ordered lists: Highest Rated, Most Viewed, and Newest. Each ordered list should have the top ten items from the database tables for story ordered according to the respective domain, i.e., either rating, views, or submission date. A list item in the list should consist of a link to the story view page presenting that story with link text the title of the story. The form mentioned above should have method control how the three top ten lists are filtered. Initially, it is blank and and "All Genres" is chosen, so no filtering is done. However, if the Phrase Filter has some non-empty value, then only stories containing that value in the title should be considered for the top ten list. Similarly, if genre is set to something other than "All Genres", then the top ten lists are restricted to just that genres. As an example, suppose the Phrase Filter was "Cute Puppies" and the genre was Crime. Then the top ten lists items would be: the Highest Rated stories with title containing "Cute Puppies" in the Crime genre, the Most Viewed stories with title containing "Cute Puppies" in the Crime genre, and the Newest stories with title containing "Cute Puppies" in the Crime genre. You should store the the current value of the Phrase Filter and Genre in a session, so that if a user comes back the values are set to what they had the last time they visited the site. Your program should clean any data sent from the form.

The Write Something View

This view should have as title "Five Thousand Characters - Write Something". This should also appear at the top of the page in a centered h1-tag, where "Five Thousand Characters" is a link taking one back to the landing page. Beneath this should be a form with three text fields, a select tag, and a textarea. The first text field should be labeled "Title", the second text field should be labeled "Author", the third text field should be labeled "Identifier", the select tag should be labeled "Genre" and it should allow multiple genre's to be select, and finally the text area should be labeled your writing. Beneath all of these items should be two buttons, a Reset and a Save button. The Reset button clears the data of the form. Clicking the Save button should save a story to the appropriate database tables. The form method should be post and the POST-REDIRECT-GET design pattern should be used. After saving, the user should still see their story and other info. Your controllers should clean any data sent from this form, there should be a fixed maximum length for each of the fields which is specified in your configs/Config.php file, and the maximum length of the textarea data should be 5000 characters. You should display some kind of error generated by the server (not client side) if data size limits were exceeded. If a user clicks on Write Something! on the landing page and comes to this view where nothing is filled in, enters an identifier, and clicks Save; your program should try to look up in the database to find a story with that identifier, and if so, show all the fields of that story for editing.

The Read A Story View

This view is reached when someone clicks on a story link from the landing page. This view should have as title "Five Thousand Characters - Story Title". Here "Story Title" is the title of the story that the link from the landing page had. "Five Thousand Characters - Story Title" should also appear at the top of the page in a centered h1-tag, where "Five Thousand Characters" is a link taking one back to the landing page. Beneath this centered in a div tag should appear the author, and beneath this the date the story was first saved. Finally, beneath this there should be the text "Your rating:" followed by the numbers 1 to 5 and then "Average Rating:" followed by the current average rating. If the user has already given a rating, the rated number should be in bold face and none of the numbers should be links. If the user has not rated the story, each of these numbers should be links. When a user clicks a rating's link, two columns in a database table row associated with the stories identifier should be adjusted: the SUM_OF_RATINGS_SO_FAR and the NUMBER_OF_RATINGS_SO_FAR. These two values are used to compute the current average rating. To prevent, in a crude way, people from voting multiple times and to decide whether to display rating's links or not, you should store in the current session the identifiers of the stories that the current user has rated. Under the ratings info should appear the actual story that was saved. This should appear in a sequence of paragraph tags. New paragraphs should be output whenever the original text that was saved had two consecutive new line characters.

How I Want Your Code Organized

You should submit a zip for your homework in Hw3.zip. Your project should be written using namespaces. You are allowed to create variables and array, objects, in the namespace cool_name_for_your_group\hw3 and subnamespaces thereof. Your project directory structure should look like:
index.php -- entry point into your project. No other file in your project should be directly linked-to.
    All urls used as links by your project should be in the format:
    BASE_URL/index.php?c=name_of_controller&m=name_of_method&arg1=value_for_arg1& ...&argn=value_for_argn 
src
 |-configs -- should have a Config.php class with constants for things like database user, password, host, port, etc.
 |            Basically, it should have anything you think the grader might need to get your program running on my machine.
 |            It should have a script CreateDB.php which can be run from the command-line to make a good initial
 |            database. Your database tables
 |-controllers -- should contain all the controller classes you write, one per file
 |-models -- should contain all the model classes you write, one per file
 |-resources -- should contain any resources used by your app such as images
 |-styles -- should have any external stylesheets you need
 |-views -- should contain all the view classes you write, one per file
      |-elements -- should contain all the element classes you write, one per file
      |-helpers -- should contain all the helper classes you write, one per file    

For this project we assume the DBMS being used is MySql. Unless stated otherwise all persistent information in this project should be stored in database tables. All of database tables should be in BCNF. You should make base classes Controller, Model, View, Element, and Helper. The namespaces for these and their subclasses should be respectively: cool_name_for_your_group\hw3\controllers, cool_name_for_your_group\hw3\models, cool_name_for_your_group\hw3\views, cool_name_for_your_group\hw3\views\elements, and cool_name_for_your_group\hw3\views\helpers. Your project should use the Model View Adapter pattern that we have discussed in class. Only controller classes are allowed to directly handle request/form data. A controller can use this information to make database calls to get/set/update info in the database, then choose a view, instantiate it, and call its render method to display a web page back to the requesting browser. Only subclasses of Model are allowed to interact with the database. Controllers should make sure to sanitize and validate user data, for example, using filter_var, filter_input, or filter_input_array functions. The base Model class should have methods for performing the initial connection to the database. Only subclasses of View, Element, and Helper are allowed to render HTML. Subclasses of View are responsible for drawing one complete web page. The base class should have a public abstract method render($data) which is implemented in sub-classes. This method should mainly run in PHP copy mode (not interpreted mode) and contain mainly HTML. You are allowed method calls (no recursion) and if-elseif-else constructs, but no looping. A subclass Element is used to encapsulate a reusable fragment of a webpage (for example, a signin form) which might appear on multiple views. The base class should have a public field $view which is initialized in the base constructor to point to the view the element is currently on. The base Element class should also have an public abstract method render($data). A subclass of Controller is not allowed to directly instantiate a subclass of Element, but a subclass of View can. As with views, elements are allowed method calls and if-elseif-else constructs, but no looping. The render method again should mainly use PHP copy mode to output HTML. Finally, subclasses of Helper are used to output common widgets which may appear on views or elements and may require iterating over data in an array to output. For example, outputting a select tag dropdown with many options coming from a field in $data. Another example might be to output the rows of a table based on an field from $data. The Helper base class should also have an abstract method public abstract method render($data). Only views and elements are allowed to instantiate helpers. The render method of a helper is allowed to use looping.

Point Breakdown

index.php sole entry point into website (1/2pt). All urls used in the project follow format described (1/2pt).1pt
Project files and classes organized as above (1/2pt). Namespaces on files as described (1/2pt).1pt
Genre types (1/2pt), Write Something form data (1/2pt), and Read Something rating data (1/2pt) persistently stored in Mysql DBMS in BCNF tables (1/2pt)2pts
Landing view general appearance as described (1/2pt), three ordered lists contain links to stories ordered as described (1/2pt)1pt
Landing page Phrase Filter and Genre form works as described.1pt
Sessions are used to remember Phrase Filter and Genre settings (1/2pt) and are used to remember if the current user voted on a given story (1/2pt).1pt
Write Something View appearance as described (1/2pt). Write Something form Reset and Save buttons work as described with POST-REDIRECT-GET design pattern on save (1/2pt). 1pt
Before persisting form data, data is cleaned and checked as described, if not of the correct format then an error message is given (1/2pt). Look up story by identifier works as by identifier works as described (1/2pt).1pt
Read Something View appearance as described (1/2pt). Ratings links and storage works as described. (1/2pt) 1pt
Total10pts